package com.dsh.subscribe.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.dsh.subscribe.entity.HealthCareProgram;
import com.dsh.subscribe.dao.HealthCareProgramDao;
import com.dsh.subscribe.entity.vo.*;
import com.dsh.subscribe.service.HealthCareProgramService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 健康医疗项目(HealthCareProgram)表服务实现类
 *
 * @author makejava
 * @since 2022-04-29 09:17:35
 */
@Service("healthCareProgramService")
public class HealthCareProgramServiceImpl implements HealthCareProgramService {
    @Resource
    private HealthCareProgramDao healthCareProgramDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public HealthCareProgramVo queryById(Integer id) {
        HealthCareProgramVo healthCareProgramVo = healthCareProgramDao.queryById(id);
        return healthCareProgramVo;
    }

    /**
     * 查询多条数据
     *
     *
     * @param limit 查询条数
     * @return 对象列表
     */
    @Override
    public PageInfo<HealthCareProgram> queryAllByLimit(String projectName,String typeName,int page, int limit) {
        PageHelper.startPage(page,limit);
        if ((projectName == null) && (typeName == null)) {
            List<HealthCareProgram> healthCareProgram = healthCareProgramDao.queryAllByLimit();
            return new PageInfo<>(healthCareProgram);
        }
        else {
            List<HealthCareProgram> healthCarePrograms = healthCareProgramDao.queryAllByLimitM(projectName, typeName);
            return new PageInfo<>(healthCarePrograms);
        }

    }

    /**
     * 新增数据
     *
     * @param healthCareProgram 实例对象
     * @return 实例对象
     */
//    @Override
//    public int insertHealthCareProgram(HealthCareProgramVo healthCareProgramVo) {
//        int insert = healthCareProgramDao.insert(healthCareProgramVo);
//        return insert;
//    }

    /**
     * 修改数据
     *
     * @return 实例对象
     */
    @Override
    public int update(HealthCareProgramVo healthCareProgramVo) {
        healthCareProgramVo.setShopName(JSONObject.toJSONString(healthCareProgramVo.getShopNames()));
        int update = healthCareProgramDao.update(healthCareProgramVo);
        return update;
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {

        return this.healthCareProgramDao.deleteById(id) > 0;
    }


    /**
     * 改变健康管理项目的状态
     */
    @Override
    public int updateStatus(int id) {
        int i = healthCareProgramDao.updateStatus(id);
        return i;
    }

    @Override
    public List<HealthType> selectAllType() {
        List<HealthType> healthTypes = healthCareProgramDao.selectAllType();
        return healthTypes;
    }

    @Override
    public int insertProgram(HealthCareProgramVo healthCareProgramVo) {
        healthCareProgramVo.setShopName((JSONObject.toJSONString(healthCareProgramVo.getShopNames())));
        int i = healthCareProgramDao.insertProgram(healthCareProgramVo);
        return i;
    }

    @Override
    public PhysiotherapyCountVo selectPhysiotherapyCount() {
        PhysiotherapyCountVo physiotherapyCountVo = healthCareProgramDao.selectPhysiotherapyCount();
        return physiotherapyCountVo;
    }

    @Override
    public int insertSonType(SonTypeVo sonTypeVo) {
        int i = healthCareProgramDao.insertSonType(sonTypeVo);
        return i;
    }

    @Override
    public int updateSonType(SonTypeVo sonTypeVo) {
        int i = healthCareProgramDao.updateSonType(sonTypeVo);
        return i;
    }

    @Override
    public int insertType(TypeVo typeVo) {
        int i = healthCareProgramDao.insertType(typeVo);
        return i;
    }

    @Override
    public int updateType(TypeVo typeVo) {
        int i = healthCareProgramDao.updateType(typeVo);
        return i;
    }

}